from sqlalchemy import Column, INTEGER
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy_dm import VARCHAR2, DATE, NUMBER

# 创建对象的基类
Base = declarative_base()

# 生成结果历史类
class ChupbModel(Base):
    # 模式名
    __table_args__ = {'schema': 'ESUNTEST'}
    # 表名
    __tablename__ = 'HX_BI_CHUPB'
    # 表结构
    ID = Column(INTEGER, primary_key=True, autoincrement=True)
    CHUPRQC = Column(VARCHAR2(256))
    PJLB = Column(VARCHAR2(100))
    PJHM = Column(VARCHAR2(256))
    CPR = Column(DATE)
    DQR = Column(DATE)
    PMJE = Column(NUMBER)
    SKRQC = Column(VARCHAR2(256))

    @classmethod
    def from_dict(cls, data):
        return cls(
            ID=int(data.get('ID')) if data.get('ID') is not None else 0,
            CHUPRQC=data.get('CHUPRQC'),
            PJLB=data['PJLB'],
            PJHM=data['PJHM'],
            CPR=data['CPR'],
            DQR=data['DQR'],
            PMJE=data['PMJE'],
            SKRQC=data['SKRQC'],
        )
    def to_dict(self):
        return {
            'ID': self.ID,
            'CHUPRQC': self.CHUPRQC,
            'PJLB': self.PJLB,
            'PJHM': self.PJHM,
            'CPR': self.CPR,
            'DQR': self.DQR,
            'PMJE': self.PMJE,
            'SKRQC': self.SKRQC,
        }